<template>
    <div>
        <Modal v-model='modal' title='管理工具箱' :mask-closable='false' @on-cancel='canceledit' footer-hide  width="580">

            <div>
                <span>当前域名：</span><span>{{title}}</span>
            </div>
            <div class="ivu-mt-16">
                <Button  @click="clickmodal(1)"  v-hasC="{name: '-v1-site-index-recreate-local-ftp',flag: '/v1/site/index/recreate-local-ftp'}">重置本地FTP</Button>
                <Button  class="ivu-ml-16" @click="clickmodal(2)"  v-hasC="{name: '-v1-site-index-recreate-online-ftp',flag: '/v1/site/index/recreate-online-ftp'}">重置线上FTP</Button>
                <Button  class="ivu-ml-16" @click="clickmodal(3)" v-hasC="{name: '-v1-site-index-recreate-db',flag: '/v1/site/index/recreate-db'}" :disabled="+db_type===4">重置独立数据库</Button>
                <Button  class="ivu-ml-16" @click="clickmodal(4)" v-hasC="{name: '-v1-site-index-delete-true',flag: '/v1/site/index/delete-true'}">彻底删除站点</Button>
                 <div  class="ivu-mt-16 ivu-mb-16">
                    <Button  @click="clickmodal(5)"  style="width:115px"  v-hasC="{name: '-v1-site-index-init-site',flag: '/v1/site/index/init-site'}">站点初始化</Button>
                </div>
            </div>
            <div class="box">
                <div class="rignt-box">
                    <ul>
                        <li><b>重置本地FTP：</b>针对当前站点本地FTP无法打开时，重新创建FTP账号。</li>
                        <li><b>重置线上FTP：</b>针对当前站点线上FTP无法打开时，重新创建FTP账号。</li>
                        <li><b>重置数据库：</b>
                            <p style="text-indent:25px">当站点为独立数据库时，将删除当前数据库，重新初始化成新的空数据库；</p>
                            <p style="text-indent:25px"> 当站点为共享数据库时，无法重置，该功能失效；</p>
                            <p style="text-indent:25px"> 当站点为复用数据库时，将重新生成被复用的站点数据库为当前站点数据库。</p>
                        </li>
                        <li><b>彻底删除站点：</b>将站点相关的所有文件（包括数据库）全部删除 【无法恢复】。</li>
                        <li><b>站点初始化：</b>实现效果： 等同于”彻底删除站点“功能 ，然后自动重新创建该站点。</li>
                    </ul>
            </div>
            </div>
        </Modal>
        <Modal v-model='modalstatus' :title='titleName' :mask-closable='false' @on-cancel='cancel' width="420">
            <p v-if="titleName=='重置本地FTP'">确定重置本地FTP？</p>
            <p v-if="titleName=='重置线上FTP'">确定重置线上FTP？</p>
            <p v-if="titleName=='重置独立数据库'">确定重置独立数据库？</p>
            <p v-if="titleName=='彻底删除站点'">确定彻底删除站点？</p>
            <p v-if="titleName=='站点初始化'">确定站点初始化？</p>
            <div slot='footer'>
                <Button @click='cancel()'>取消</Button>
                <Button type='primary' :loading="subloading" @click='submitedit()'>保存</Button>
            </div>
        </Modal>
    </div>
</template>

<script>
    import { reateLocalftptus, recreateOnlineftp, recreatedb, deletetrue, initsite } from '@api/httpsetting'
    export default {
        name: '',
        components: {},

        data () {
            return {
                modalstatus: false,
                titleName: '',
                modal: false,
                subloading: false,
                title: '',
                list: null,
                modalparams: { id: '' },
                db_type:''
            };
        },
        // created () {
        //     this.initial()
        // },
        /* 函数方法集合 */
        methods: {
            /* @函数功能: 初始化 */
            initial (row) {
                this.modalparams.id = row.id
                this.title = row.domain
                this.db_type=row.db_type
                this.modal = true
                // this.getcheck()
            },
            canceledit () {
                this.modal = false
                this.localftp = false
                this.onlineftp = false
                this.createdb = false
                this.deletetrue = false
                this.initsite = false
            },
            clickmodal (num) {
                if (num === 1) {
                    this.titleName = '重置本地FTP'
                } else if (num === 2) {
                    this.titleName = '重置线上FTP'
                } else if (num === 3) {
                    this.titleName = '重置独立数据库'
                } else if (num === 4) {
                    this.titleName = '彻底删除站点'
                } else if (num === 5) {
                    this.titleName = '站点初始化'
                }
                this.modalstatus = true
            },
            cancel () {
                this.modalstatus = false
                this.subloading = false
                // this.modal = false
            },
            submitedit () {
                if (this.titleName === '重置本地FTP') {
                    this.subloading = true
                    reateLocalftptus({ id: this.modalparams.id }).then(res => {
                        this.$Message.success('重置本地FTP成功')
                        this.cancel()
                        this.modal = false
                        this.$emit('askData')
                    })
                } else if (this.titleName === '重置线上FTP') {
                    this.subloading = true
                    recreateOnlineftp({ id: this.modalparams.id }).then(res => {
                        this.$Message.success('重置线上ftp成功')
                        this.cancel()
                        this.modal = false
                        this.$emit('askData')
                    })
                } else if (this.titleName === '重置独立数据库') {
                    this.subloading = true
                    recreatedb({ id: this.modalparams.id }).then(res => {
                        this.$Message.success('重置数据库成功')
                        this.cancel()
                        this.modal = false
                        this.$emit('askData')
                    })
                } else if (this.titleName === '彻底删除站点') {
                    this.subloading = true
                    deletetrue({ id: this.modalparams.id }).then(res => {
                        this.$Message.success('彻底删除站点成功')
                        this.cancel()
                        this.modal = false
                        this.$emit('askData')
                    })
                } else if (this.titleName === '站点初始化') {
                    this.subloading = true
                    initsite({ id: this.modalparams.id }).then(res => {
                        this.$Message.success('初始化站点成功')
                        this.cancel()
                        this.modal = false
                        this.$emit('askData')
                    })
                }
            }
        }
    }
</script>
<style scoped>
.box{
 border: 1px dashed #3d3d41;
}
.rignt-box{
  padding: 20px 0 20px 29px;
  line-height: 30px;
}
</style>
